<?php
/**
 * Class oeUser
 * @method string getId()
 * @method string getName()
 * @method string getUsername()
 * @method string getEmail()
 * @method string getPassword()
 * @method string getUserType()
 * @method string getLastFailedLogin()
 * @method string getStatus()
 * @method string setName()
 * @method string setUsername()
 * @method string setEmail()
 * @method string setPassword()
 * @method string setUserType()
 * @method string setLastFailedLogin()
 * @method string setStatus()
 */
class oeUser extends dbObject {

	const USER_USERTYPE_EXAMINEE = 0;
	const USER_USERTYPE_MARKER = 1;
	const USER_USERTYPE_INSTRUCTOR = 2;
	const USER_USERTYPE_ADMIN = 3;
	
	const USER_STATUS_ACTIVE = 0;
	const USER_STATUS_DISABLE = 1;
	const USER_STATUS_HIDDEN = 2;

    // login salt for security purposes
    private $loginSalt = 'agt22';
	
	public static function create($params) {
			
		$obj = new oeUser();	
		if (isset($params['id'])) {
			$obj = new oeUser($params['id']);
		} else {
			$obj->setPassword($params['password']);
		}
		
		$obj->setName($params['name']);
		$obj->setUsername($params['username']);
		$obj->setEmail($params['email']);
		$obj->setPassword($params['password']);
		$obj->setUserType($params['userType']);
		$obj->setStatus($params['status']);
		$obj->commit();
		
		return $obj->getId();
	}

    public function isPasswordCorrect($password) {
        return md5($this->loginSalt . $password . $this->loginSalt) == $this->getPassword();
    }

    public function setPassword($password) {
      parent::setPassword(md5($this->loginSalt . $password . $this->loginSalt));
    }

	public function isExaminee() {
		
	}
	
	public function isMarker() {
		
	}
	
	public function isInstructor() {
		
	}
	
	public function isAdmin() {
		
	}
	
	public function isActive() {
		
	}
	
	public function isDisable() {
		
	}
	
	public function isHidden() {
		
	}
}